package auth

import (
	"context"

	UserAuthClient "gitee.com/liuxuezhan/ar-platform/rpc-client/userAuthClient/client/auth"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 用户实名认证-更新
func NewUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateLogic {
	return &UpdateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UpdateLogic) Update(req *types.UserAuthUpdateRequest) (resp *types.UserAuthUpdateResponse, err error) {
	_, err = l.svcCtx.UserAuth.Update(l.ctx, &UserAuthClient.UpdateReq{
		UserId:   req.Id,
		RealName: req.Name,
		Idcard:   req.CPF,
	})
	if err != nil {
		return nil, err
	}
	return &types.UserAuthUpdateResponse{}, nil
}
